const getters = {
  // 购物车模块
  shopCar: state => state.cart.shopCar,
  // 选中的商品记录
  selectedRecords: state => {
    let selected = [];
    state.cart.shopCar.forEach(item => {
      if (item.select) {
        selected.push(item.id);
      }
    });
    return selected;
  },
  shopSelect: state => {
    // 对应id项的选中状态    /* { id: boolean } */
    let sel = {};
    state.cart.shopCar.forEach(item => {
      sel[item.id] = item.select;
    });
    return sel;
  },
  shopCount: state => {
    // 当前商品id所对应的数量  { id: count}
    let count = {};
    state.cart.shopCar.forEach(item => {
      count[item.id] = item.count;
    });
    return count;
  },
  shopCountAll: state => {
    // 分发所有加入购物车的商品的总数量
    let num = 0;
    state.cart.shopCar.forEach(item => {
      num += item.count;
    });
    return num;
  },
  shopSel: state => {
    // 分发选中状态的数据的数量 / 价格
    let obj = {
      // 默认未勾选
      count: 0,
      total: 0
    };
    state.cart.shopCar.forEach(item => {
      if (item.select) {
        // 如果是选中状态
        obj.count += item.count; // 选中数据的数量累计
        obj.total += (parseInt(item.count) * item.sell_price * 100) / 100; // 选中数据的 总价累计
      }
    });
    return obj;
  },
  // 购物车中选中的商品列表
  cartSelectedList: state => {
    return state.cart.shopCar.filter(item => {
      return item.select;
    });
  }
};
export default getters;
